﻿$.MGJ.AntiFakeVerify = [];
(function () {
    var _this = $.MGJ.AntiFakeVerify;
    $.extend($.MGJ.AntiFakeVerify, {
        //防伪信息查询
        Ajax_GetAntiFakeInfo: function (Code) {
            $.L.ajaxHandle({
                url: ACTION_URL("Selest", "AntiFake"),
                data: {
                    Code: Code,
                },
                success: function (data) {
                    
                    if (data) {
                        var Thedata = JSON.parse(data);
                        var the_data = JSON.parse(Thedata.results);
                        if (Thedata.results == "6")
                        {
                            $.L.msgWarning('防伪码不能为空！')
                        }
                      
                        if (Thedata.results != "-1") {

                            if (Thedata.results == "2") {
                                $("#AntiFakeInfoCon").show()
                                $("#T_F").css({ "background": "red", "color": "red" })
                                $("#T_F_Child").html("错误")
                                $("#Particulars").hide();
                                $("#QueryLog").hide();
                                $("#QueryLogUl").hide();
                                $(".The_P").text("尊敬的消费者您好!您查询的产品已实施召回，请联系当地销售商做退回处理！").parent().css('min-height', '420px');

                            }
                            else {
                                //if (Thedata.num == 1) {
                                //获取时间
                                function p(s) {
                                    return s < 10 ? '0' + s : s;
                                }
                              
                                
                                $("#AntiFakeInfoCon").show();
                                var myDate = new Date();
                                var year = myDate.getFullYear();
                                var month = myDate.getMonth() + 1;
                                var date = myDate.getDate();
                                var h = myDate.getHours();
                                var m = myDate.getMinutes();
                                var s = myDate.getSeconds();
                                var NowTime = year + '-' + p(month) + "-" + p(date) + " " + p(h) + ':' + p(m) + ":" + p(s);
                                if (the_data[0].LabelImage != "") {
                                    $("#QrCodeImg").attr("src", the_data[0].LabelImage);
                                } else {
                                    $("#QrCodeImg").attr("src", "/Content/webImgs/AntiFake/empty.png");
                                }
                                
                                $("#T_F_Child").html("正品")
                                if (the_data[0].EnterpriseUse == "") {
                                    $("#EnterpriseUse").html(the_data[0].EnterpriseName)
                                }
                                else {
                                    $("#EnterpriseUse").html(the_data[0].EnterpriseUse)
                                }

                                if (the_data[0].ProductName == "") {
                                    $(".BrandNames").html("产品暂未绑定")
                                } else {
                                    $(".BrandNames").html(the_data[0].ProductName)
                                }
                                $("#QueriesNub").html(Thedata.num)
                                $("#FirstQueries").html(NowTime)
                                $("#T_F").css({ "background": "green", "color": "green" })
                                _this.Ajax_GetAntiFakeNum(Code)
                                
                                if (the_data[0].Query_Result_Content != "") {
                                    
                                    $(".The_P").html(the_data[0].Query_Result_Content + "")
                                } else if (the_data[0].EnterpriseUse == "") {
                                    $(".The_P").html("您所查询的是" + the_data[0].EnterpriseName + "的正牌产品，谨防假冒！如有疑问请拨打(" + the_data[0].EnterpriseName + ")的售后服务热线！")
                                }

                                $("#QueryLog").show()
                                $("#QueryLogUl").hide()

                               
                                _this.Ajax_GetAntiFakeNum(Code)
                                
                            }
                        }
                    
                    else if (Thedata.results == "-1") {
                        $("#T_F").css({ "background": "red", "color": "red" })
                        $("#T_F_Child").html("错误")
                        $("#Particulars").hide();
                        $("#QueryLog").hide();
                        $("#QueryLogUl").hide();
                        $("#AntiFakeInfoCon").show();
                      

                        if (Thedata.res == "" || Thedata.res == null) {
                            $(".The_P").text('您所查询的防伪码不存在，防伪码应是不含空格的纯数字编码，请核对，谨防假冒！').parent().css('min-height', '420px');
                        } else {
                            $(".The_P").text(Thedata.res).parent().css('min-height', '420px');
                        }
                    }
                        }
                    
                    else {
                        $("#AntiFakeInfoCon").hide()
                        $.L.msgError("该码不属于当前企业")
                    }
                
                }
                ,

             });
        },
        //查询防伪记录的次数
        Ajax_GetAntiFakeNum: function (SeachStr) {
            $.L.ajaxHandle({
                url: ACTION_URL("GetCodeLogDis", "AntiFake"),
                data: {
                    Code: SeachStr,

                }, success: function (response) {

                    the_response_ = JSON.parse(response);
                    the_response = JSON.parse(the_response_.info)

                    if (response != -1) {
                        $("#QueryLogUl").children().remove();
                        $(".triangle-down").toggleClass("triangle-down").toggleClass("triangle-right")
                        for (var i = 0; i < the_response.length; i++) {
                            var $li = "<li><span>第" + (i + 1) + "次查询</span><span>" + the_response[i].QueryProvince + "/" + the_response[i].QueryCity + "</span><span>" + the_response[i].QueryTime + "</span></li>"
                           
                            $("#QueryLogUl").append($li)
                        }
                    }
                }
            });
        },

    });
})(jQuery);

$(".QueryLogUlBtn").on("click", function () {
    $("#QueryLogUl").toggle()
    $(".QueryLogUlBtn").toggleClass("triangle-right").toggleClass("triangle-down")
})